package 每日一题;

import java.util.Scanner;

public class 进制转换 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int m=sc.nextInt();//待转换的数字
        int n=sc.nextInt();//转换的进制

        if (m==0) {
            System.out.println(m);
        }

        String table="0123456789ABCDEF";  //进制N为 (2 ≤ N ≤ 16)
        boolean flag=false;
        if (m<0) {
            flag=true;
            m=-m;
        }

        StringBuilder str=new StringBuilder();
        while (m!=0) {
            str.append(table.charAt(m%n));
            m=m/n;
        }

        if (flag) {
            str.append('-');
        }

        str.reverse();
        System.out.println(str);

    }
}
